package com.tongguan.paypos.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.tongguan.paypos.R;
import com.tongguan.paypos.entity.PayType;

import java.util.ArrayList;

/**
 * Created by Joylive on 2016/12/7 .
 */

public class PayTypeAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<PayType> mDatas;

    public PayTypeAdapter(Context context, ArrayList<PayType> datas) {
        this.context = context;
        this.mDatas = datas;
    }

    @Override
    public int getCount() {
        if (mDatas != null && mDatas.size() > 0)
            return mDatas.size();
        else
            return 0;
    }

    @Override
    public PayType getItem(int position) {
        if (mDatas != null && mDatas.size() > 0)
            return mDatas.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView =LayoutInflater.from(context).inflate(R.layout.item_img_gv, null);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_gv_item);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        int resId = mDatas.get(position).getResId();
        holder.mImageView.setImageResource(resId);
        return convertView;
    }

   private class Holder {
        ImageView mImageView;
    }

}
